package com.itcms.core.web.back;

import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;

import com.itcms.common.util.ReadConfig;
import com.itcms.core.domain.Role;
import com.itcms.core.domain.User;
import com.itcms.core.domain.UserTodoTotal;
import com.itcms.core.service.RoleService;
import com.itcms.core.service.UserService;
import com.itcms.core.service.UserTodoTotalService;
import com.itcms.webservice.util.WSClientUtil;
import com.itcms.webservice.uuv.todoCount.SendTodoCountResponse.SendTodoCountResult;
import com.itcms.webservice.uuv.todoCount.TodoCountServiceSoap;

@Controller
@Lazy(false)
public class TodoCountTask {
	public static final int[] ROLE_ID = {8,9,10};
//	@Scheduled(cron = "0/5 * * * * ?")   //每10秒执行一次  
	public void testTask() {
		System.out.println("定时执行额0。");
	}
	
	@Transactional
//	@Scheduled(cron = "0/10 * * * * ?")    //每10秒执行一次  
	public void testTask1() {
//		User user = service.findByUsername("admin");
//		System.out.println("User:"+user.getUsername());
		List<Role> roles = roleService.findList(5);
		System.out.println("先输出角色");
		for (Role role : roles) {
			if(ArrayUtils.contains(ROLE_ID, role.getId())){
				Set<User> users = role.getUsers();
				for (User user : users) {
					String loginID = user.getUsername();
					String userCode = user.getUserCode();
					System.out.println(loginID+" : "+userCode);
				}
			}
		}
	}
	
	@Transactional
//	@Scheduled(cron = "0 0/15 * * * ?")   //每15分执行任务
	public void todoTotal() {
		//往oa推送待办
		userTodoTotalService.sendTodo();
	}
	
	@Autowired
	private UserService service;
	@Autowired
	private RoleService roleService;
	@Autowired
	private UserTodoTotalService userTodoTotalService;
}
